#ifndef _GQUEUE_H_
#define _GQUEUE_H_

template<typename T>
class BBQueue
{
public:
	BBQueue(void);
	~BBQueue(void);
	void enqueue(T obj);
	bool isEmpty();
	T dequeue();
	int size();

private:
	struct NodeItem
	{
		T data;
		NodeItem* next;
	};
	NodeItem* frontNode;
	NodeItem* backNode;
	int count;
};


template<typename T>
BBQueue<T>::BBQueue( void ):frontNode(0),backNode(0),count(0)
{

}

template<typename T>
BBQueue<T>::~BBQueue( void )
{

}


template<typename T>
bool BBQueue<T>::isEmpty()
{
	return count == 0;
}


template<typename T>
void BBQueue<T>::enqueue( T obj )
{
	NodeItem* item = new NodeItem();
	item->data = obj;
	item->next = 0;
	if(isEmpty())
		frontNode = item;
	else
		backNode->next = item;
	backNode = item;
	count++;
}

template<typename T>
T BBQueue<T>::dequeue()
{
	if(isEmpty())
		return 0;
	NodeItem* temp = frontNode;
	T data = temp->data;
	if(frontNode == backNode)
	{
		frontNode = 0;
		backNode = 0;
	}
	else
		frontNode = frontNode->next;
	delete temp;
	count--;
	return data;
}

#endif _GQUEUE_H_